package com.wenjie.original.service.impl;


import com.wenjie.common.utils.TokenUtil;
import com.wenjie.original.entity.SysAdmin;
import com.wenjie.original.entity.SysLogLogin;
import com.wenjie.original.flex_config.baseInterface.Cus_ServiceImp;
import com.wenjie.original.mapper.SysLogLoginMapper;
import com.wenjie.original.service.ISysLogLoginService;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * 登录日志 服务层处理
 *
 * @author wenjie
 */
@Service
public class SysLogLoginServiceImpl extends Cus_ServiceImp<SysLogLoginMapper, SysLogLogin> implements ISysLogLoginService {
    /**
     * @Description 添加一下系统的登录记录
     * @author wenjie
     * @date 2024/8/26 15:24
     */
    public void sucInfo(SysAdmin sysAdmin) {

        HttpServletRequest request = TokenUtil.getRequest();
        String remoteAddr = request.getRemoteAddr();

        // 查询一下ip的地址信息
//        JSONObject dataObject = IpUtils.getAddrByIp(remoteAddr);
//        String addr = null;
//        if (dataObject != null) {
//            String region = dataObject.getStr("region");// 省
//            String city = dataObject.getStr("city");// 市
//            String district = dataObject.getStr("district");// 区
//            addr = region + "-" + city + "-" + district;
//        }


        SysLogLogin sysLogLogin = new SysLogLogin();
        sysLogLogin.setSysAdminId(sysAdmin.getSysAdminId());
        sysLogLogin.setTel(sysAdmin.getTel());
        sysLogLogin.setName(sysAdmin.getName());
        sysLogLogin.setStatus(SysLogLogin.STATUS.arg0);
        sysLogLogin.setIpaddr(remoteAddr);
//        sysLogLogin.setLoginLocation(addr);
//        sysLogLogin.setLng(dataObject.getStr("lng"));
//        sysLogLogin.setLat(dataObject.getStr("lat"));
        this.save(sysLogLogin);
    }

    public void failInfo() {
        HttpServletRequest request = TokenUtil.getRequest();
        String remoteAddr = request.getRemoteAddr();

        // 查询一下ip的地址信息
//        JSONObject dataObject = IpUtils.getAddrByIp(remoteAddr);
//        String addr = null;
//        if (dataObject != null) {
//            String region = dataObject.getStr("region");// 省
//            String city = dataObject.getStr("city");// 市
//            String district = dataObject.getStr("district");// 区
//            addr = region + "-" + city + "-" + district;
//        }

        SysLogLogin sysLogLogin = new SysLogLogin();
        sysLogLogin.setStatus(SysLogLogin.STATUS.arg1);
        sysLogLogin.setIpaddr(remoteAddr);
//        sysLogLogin.setLoginLocation(addr);
//        sysLogLogin.setLng(dataObject.getStr("lng"));
//        sysLogLogin.setLat(dataObject.getStr("lat"));
        this.save(sysLogLogin);
    }

}
